package com.tuanzi.loan.business.repository.family.impl;

import com.tuanzi.loan.business.repository.family.custom.LoanLargeAmountNewPartnerInfoRepositoryCustom;
import com.tuanzi.loan.core.repository.JOOQBaseRepositoryPlus;
import com.tuanzi.loan.vo.request.Collaborate.LargeAmountNewPartnerRequest;
import com.tuanzi.loan.vo.response.collaborate.LargeAmountNewPartnerResponse;
import org.jooq.impl.TableImpl;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Repository;

import static com.tuanzi.loan.generated.jooq.loan.Tables.LOAN_LARGE_AMOUNT_NEW_PARTNER_INFO;

/**
 * User: liangZongXi
 * Create time: 10:59 2019/8/21
 * Description:
 */
@Repository
public class LoanLargeAmountNewPartnerInfoRepositoryImpl extends JOOQBaseRepositoryPlus implements LoanLargeAmountNewPartnerInfoRepositoryCustom {
    @Override
    public Page<LargeAmountNewPartnerResponse> list(LargeAmountNewPartnerRequest searchRequest, Pageable pageable) {
         fields(LOAN_LARGE_AMOUNT_NEW_PARTNER_INFO.ID, LOAN_LARGE_AMOUNT_NEW_PARTNER_INFO.PARTNER_ACCOUNT,
                 LOAN_LARGE_AMOUNT_NEW_PARTNER_INFO.CHANNEL_ND_INFO);

         contains(LOAN_LARGE_AMOUNT_NEW_PARTNER_INFO.PARTNER_ACCOUNT, searchRequest.getAccount());
         contains(LOAN_LARGE_AMOUNT_NEW_PARTNER_INFO.CHANNEL_ND_INFO, searchRequest.getChannel());

         orderBy(LOAN_LARGE_AMOUNT_NEW_PARTNER_INFO.CREATE_TIME, Sort.Direction.DESC);

        return search(pageable, record -> {
            LargeAmountNewPartnerResponse response = new LargeAmountNewPartnerResponse();
            response.setId(record.get(LOAN_LARGE_AMOUNT_NEW_PARTNER_INFO.ID));
            response.setAccount(record.get(LOAN_LARGE_AMOUNT_NEW_PARTNER_INFO.PARTNER_ACCOUNT));
            response.setChannelNdInfo(record.get(LOAN_LARGE_AMOUNT_NEW_PARTNER_INFO.CHANNEL_ND_INFO));
            return response;
        });
    }

    @Override
    protected TableImpl getTable() {
        return LOAN_LARGE_AMOUNT_NEW_PARTNER_INFO;
    }
}
